/*
Author : Nguyen Van Ty
Email  : ngvanty03@gmail.com
Date   : 12/19/2010 

*/

using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using BusinessObject;
using Utility;
using System.Xml;
namespace DataAccessLayer
{
    /// <summary>
    /// Define MatHangDaoBase class. This class user for DataAccessLayer, contain 4 function Insert, Update, Search, Delete.
    /// If you want add new function, you must define in MatHangDao class , not here.
    /// </summary>
    public class MatHangDaoBase
    {
        private static ILog logger = null;
        #region Constructor
        /// <summary>
        /// Define Constructor.
        /// </summary>
        public MatHangDaoBase() { }
        static MatHangDaoBase()
        {
            //Init logger.
            logger = LoggingUtility.GetLogger(typeof(MatHangDaoBase).FullName);
        }
        #endregion
        /// <summary>
        /// Read data from IDataReader, convert to MatHang Object.
        /// </summary>
        private static MatHang GetMatHangByDataReader(IDataReader reader)
        {
            String methodName = "GetMatHangByDataReader";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }
            try
            {
                MatHang result = new MatHang();
                //read MaMatHang field data.

                result.MaMatHang = ManagerDao.GetstringDataFromDataReader(reader, "MaMatHang");
                result.MaPhuTung = ManagerDao.GetstringDataFromDataReader(reader, "MaPhuTung");
                result.CurencyCode = ManagerDao.GetstringDataFromDataReader(reader, "CurencyCode");

                //read MaLoaiHangHoa field data.

                result.MaLoaiHangHoa = ManagerDao.GetintDataFromDataReader(reader, "MaLoaiHangHoa");
                result.DVT = ManagerDao.GetintDataFromDataReader(reader, "DVT");

                //read TenMatHang field data.

                result.TenMatHang = ManagerDao.GetstringDataFromDataReader(reader, "TenMatHang");

                //read MaNuocSanXuat field data.

                result.MaNuocSanXuat = ManagerDao.GetintDataFromDataReader(reader, "MaNuocSanXuat");

                //read Hieu field data.

                result.Hieu = ManagerDao.GetstringDataFromDataReader(reader, "Hieu");

                //read GhiChu field data.
                result.GiaBan = ManagerDao.GetfloatDataFromDataReader(reader, "GiaBan");
                result.GhiChu = ManagerDao.GetstringDataFromDataReader(reader, "GhiChu");

                //read Order field data.

                result.Order = ManagerDao.GetintDataFromDataReader(reader, "Order");
                result.MaXe = ManagerDao.GetintDataFromDataReader(reader, "MaXe");

                //read IsPublished field data.

                result.IsPublished = ManagerDao.GetbooleanDataFromDataReader(reader, "IsPublished");

                //read CreatedBy field data.

                result.CreatedBy = ManagerDao.GetstringDataFromDataReader(reader, "CreatedBy");

                //read CreatedDate field data.

                result.CreatedDate = ManagerDao.GetdatetimeDataFromDataReader(reader, "CreatedDate");

                //read LastUpdatedBy field data.

                result.LastUpdatedBy = ManagerDao.GetstringDataFromDataReader(reader, "LastUpdatedBy");

                //read LastUpdatedDate field data.

                result.LastUpdatedDate = ManagerDao.GetdatetimeDataFromDataReader(reader, "LastUpdatedDate");

                return result;
            }
            catch (Exception e)
            {
                // write error to log file.
                logger.Error(methodName, e);
                return null;
            }
        }
        /// <summary>
        /// Define function Insert for MatHang Object.
        /// </summary>
        /// <param name="obj">Object Insert.</param>
        /// <returns>
        ///    1: Successfull.
        ///    0: Process Error.
        ///    -1: ma Phu tung is exists
        ///    -2: Code is ecxists
        ///</returns>
        public static int Insert(MatHang obj, List<HinhAnhMatHang> lstImage)
        {
            int result = 0;
            String methodName = "InsertMatHang";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }
            ManagerDao.BeginTransaction();
            DbCommand cmd = ManagerDao.GetStoredProcCommand("spInsertMatHang");

            //Add value "MaMatHang"  paramater.
            ManagerDao.AddInParameter(cmd, "MaMatHang", DbType.AnsiString, obj.MaMatHang);
            ManagerDao.AddInParameter(cmd, "MaPhuTung", DbType.AnsiString,
                ConvertValueObject.CastObjValueToInsertDB(obj.MaPhuTung));
            ManagerDao.AddInParameter(cmd, "MaXe", DbType.Int32, obj.MaXe);
            //Add value "MaLoaiHangHoa"  paramater.
            ManagerDao.AddInParameter(cmd, "MaLoaiHangHoa", DbType.Int32,
                ConvertValueObject.CastObjValueToInsertDB(obj.MaLoaiHangHoa));
            //Add value "TenMatHang"  paramater.
            ManagerDao.AddInParameter(cmd, "TenMatHang", DbType.String,
                ConvertValueObject.CastObjValueToInsertDB(obj.TenMatHang));
            //Add value "MaNuocSanXuat"  paramater.
            ManagerDao.AddInParameter(cmd, "MaNuocSanXuat", DbType.Int32,
                ConvertValueObject.CastObjValueToInsertDB(obj.MaNuocSanXuat));
            //Add value "DVT"  paramater.
            ManagerDao.AddInParameter(cmd, "DVT", DbType.Int32,
                ConvertValueObject.CastObjValueToInsertDB(obj.DVT));

            //Add value "Hieu"  paramater.
            ManagerDao.AddInParameter(cmd, "Hieu", DbType.String,
                ConvertValueObject.CastObjValueToInsertDB(obj.Hieu));

            //Add value "GiaBan"  paramater.
            ManagerDao.AddInParameter(cmd, "GiaBan", DbType.Double,
                ConvertValueObject.CastObjValueToInsertDB(obj.GiaBan));
            ManagerDao.AddInParameter(cmd, "CurencyCode", DbType.String,
                ConvertValueObject.CastObjValueToInsertDB(obj.CurencyCode));

            //Add value "GhiChu"  paramater.
            ManagerDao.AddInParameter(cmd, "GhiChu", DbType.String,
                ConvertValueObject.CastObjValueToInsertDB(obj.GhiChu));

            //Add value "IsPublished"  paramater.
            ManagerDao.AddInParameter(cmd, "IsPublished", DbType.Boolean,
                ConvertValueObject.CastObjValueToInsertDB(obj.IsPublished));
            //Add value "CreatedBy"  paramater.
            ManagerDao.AddInParameter(cmd, "CreatedBy", DbType.String,
                ConvertValueObject.CastObjValueToInsertDB(obj.CreatedBy));
            //Add value "CreatedDate"  paramater.
            ManagerDao.AddInParameter(cmd, "CreatedDate", DbType.DateTime,
                ConvertValueObject.CastObjValueToInsertDB(obj.CreatedDate));

            //add paramater store return value.        
            ManagerDao.AddParameter(cmd, "returnValue", DbType.Int32, ParameterDirection.ReturnValue, string.Empty, DataRowVersion.Default, null);
            try
            {
                ManagerDao.ExecuteNonQuery(cmd);
                result = (int)ManagerDao.GetParameterValue(cmd, "returnValue");
                if (result > 0)
                {
                    foreach (HinhAnhMatHang objPicture in lstImage)
                    {
                        if (objPicture != null)
                        {
                            if (!HinhAnhMatHangDao.Insert(objPicture))
                            {
                                ManagerDao.Rollback();
                                return result;
                            }
                        }
                    }
                    ManagerDao.Commit();
                    return result;
                }
                else
                {
                    ManagerDao.Rollback();
                    return result;
                }

            }
            catch (Exception e)
            {
                //write error message to log file.
                logger.Error(methodName, e);
                ManagerDao.Rollback();

            }
            return result;
        }

        /// <summary>
        /// Define function Update for MatHang Object.
        /// </summary>
        /// <param name="obj">Object Update.</param>
        /// <returns>
        ///    1: Successfull.
        ///    0: Process Error.
        ///    -1: Ma Phu tung is excists
        ///</returns>
        public static int Update(MatHang obj, List<HinhAnhMatHang> lstHinhAnh)
        {
            int result = 0;
            String methodName = "UpdateMatHang";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }
            ManagerDao.BeginTransaction();
            DbCommand cmd = ManagerDao.GetStoredProcCommand("spUpdateMatHang");


            //Add value "MaMatHang"  paramater.
            ManagerDao.AddInParameter(cmd, "MaMatHang", DbType.AnsiString, obj.MaMatHang);
            ManagerDao.AddInParameter(cmd, "MaPhuTung", DbType.AnsiString, ConvertValueObject.CastObjValueToInsertDB(obj.MaPhuTung));
            ManagerDao.AddInParameter(cmd, "MaXe", DbType.Int32, ConvertValueObject.CastObjValueToInsertDB(obj.MaXe));
            //Add value "MaLoaiHangHoa"  paramater.
            ManagerDao.AddInParameter(cmd, "MaLoaiHangHoa", DbType.Int32, obj.MaLoaiHangHoa);
            //Add value "TenMatHang"  paramater.
            ManagerDao.AddInParameter(cmd, "TenMatHang", DbType.String, ConvertValueObject.CastObjValueToInsertDB(obj.TenMatHang));
            //Add value "MaNuocSanXuat"  paramater.
            ManagerDao.AddInParameter(cmd, "MaNuocSanXuat", DbType.Int32, ConvertValueObject.CastObjValueToInsertDB(obj.MaNuocSanXuat));

            ManagerDao.AddInParameter(cmd, "DVT", DbType.Int32, ConvertValueObject.CastObjValueToInsertDB(obj.DVT));

            //Add value "GiaBan"  paramater.
            ManagerDao.AddInParameter(cmd, "GiaBan", DbType.Double,
                ConvertValueObject.CastObjValueToInsertDB(obj.GiaBan));

            ManagerDao.AddInParameter(cmd, "CurencyCode", DbType.String,
                ConvertValueObject.CastObjValueToInsertDB(obj.CurencyCode));


            //Add value "Hieu"  paramater.
            ManagerDao.AddInParameter(cmd, "Hieu", DbType.String, ConvertValueObject.CastObjValueToInsertDB(obj.Hieu));
            //Add value "GhiChu"  paramater.
            ManagerDao.AddInParameter(cmd, "GhiChu", DbType.String, ConvertValueObject.CastObjValueToInsertDB(obj.GhiChu));
            //Add value "Order"  paramater.
            // ManagerDao.AddInParameter(cmd, "Order", DbType.Int32, ConvertValueObject.CastObjValueToInsertDB(obj.Order));
            //Add value "IsPublished"  paramater.
            ManagerDao.AddInParameter(cmd, "IsPublished", DbType.Boolean, obj.IsPublished);
            //Add value "CreatedBy"  paramater.
            // ManagerDao.AddInParameter(cmd, "CreatedBy", DbType.String, ConvertValueObject.CastObjValueToInsertDB(obj.CreatedBy));
            // //Add value "CreatedDate"  paramater.
            // ManagerDao.AddInParameter(cmd, "CreatedDate", DbType.DateTime, ConvertValueObject.CastObjValueToInsertDB(obj.CreatedDate));
            //Add value "LastUpdatedBy"  paramater.
            ManagerDao.AddInParameter(cmd, "LastUpdatedBy", DbType.String, ConvertValueObject.CastObjValueToInsertDB(obj.LastUpdatedBy));
            //Add value "LastUpdatedDate"  paramater.
            ManagerDao.AddInParameter(cmd, "LastUpdatedDate", DbType.DateTime, ConvertValueObject.CastObjValueToInsertDB(obj.LastUpdatedDate));
            // add parameter store return value.
            ManagerDao.AddParameter(cmd, "returnValue", DbType.Int32, ParameterDirection.ReturnValue, string.Empty, DataRowVersion.Default, null);
            try
            {
                ManagerDao.ExecuteNonQuery(cmd);
                result = (int)ManagerDao.GetParameterValue(cmd, "returnValue");
                if (result == 1)
                {
                    if (!HinhAnhMatHangDao.Delete(obj.MaMatHang))
                    {
                        ManagerDao.Rollback();
                        return 0;
                    }
                    if (lstHinhAnh != null && lstHinhAnh.Count > 0)
                    {
                        foreach (HinhAnhMatHang objPicture in lstHinhAnh)
                        {
                            if (objPicture != null )
                            {
                                if (!HinhAnhMatHangDao.Insert(objPicture))
                                {
                                    ManagerDao.Rollback();
                                    return result;
                                }
                            }
                        }

                    }
                    ManagerDao.Commit();
                    return result;
                }
                else
                {
                    ManagerDao.Rollback();
                    return result;
                }

            }
            catch (Exception e)
            {
                //write error Message to log file.
                logger.Error(methodName, e);

            }
            ManagerDao.Rollback();
            return 0;

        }
        /// <summary>
        /// Get Data MatHang object. 
        /// </summary>
        /// <param name="maMatHang" >This is primary key to get data.</param>
        /// <returns>MatHang object.</returns>

        public static MatHang Get(string maMatHang)
        {
            String methodName = "GetMatHang";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }
            try
            {
                MatHang result = null;
                DbCommand dbCommnand = ManagerDao.GetStoredProcCommand("spGetMatHang");
                //Add value "MaMatHang"  paramater.
                ManagerDao.AddInParameter(dbCommnand, "MaMatHang", DbType.AnsiString, maMatHang);
                IDataReader reader = ManagerDao.ExecuteReader(dbCommnand);
                if (reader.Read())
                {
                    result = GetMatHangByDataReader(reader);

                }
                reader.Close();
                return result;
            }
            catch (System.Exception e)
            {
                //write error message to log file.
                logger.Error("Get", e);
                return null;
            }
        }
        /// <summary>
        /// Get All MatHang object from table MatHang.
        /// </summary>
        /// <returns>List MatHang object.</returns>
        public static List<MatHangResult> GetAll()
        {
            String methodName = "GetAll";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }

            try
            {
                List<MatHangResult> listMatHang = new List<MatHangResult>();
                DbCommand dbCommand = ManagerDao.GetStoredProcCommand("spGetAllMatHang");

                using (IDataReader reader = ManagerDao.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        listMatHang.Add(GetMatHangResultByDataReader(reader));
                    }
                    reader.Close();
                }

                return listMatHang;
            }
            catch (Exception ex)
            {
                //write error message to log file.
                logger.Error(methodName, ex);
                return null;
            }
        }

        /// <summary>
        /// Search MatHang object in table MatHang with condition is t object.
        /// </summary>
        /// <param name="t">Condition for Search.</param>       
        /// <param name="totalRow">  total records in this table.</param>
        /// <returns>List MatHangResult object.</returns>
        public static List<MatHangResult> SearchMatHangSomeCondition(MatHang t)
        {
            String methodName = "SearchMatHangSomeCondition";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }

            try
            {
                List<MatHangResult> listMatHang = new List<MatHangResult>();
                DbCommand cmd = ManagerDao.GetStoredProcCommand("spSearchMatHangByCondition");
                //Add value Condition  paramater.
                ManagerDao.AddInParameter(cmd, "Condition", DbType.String, ConvertValueObject.CastObjValueToInsertDB(t.Condition));

                //Add value PageIndex  paramater.
                ManagerDao.AddInParameter(cmd, "PageIndex", DbType.Int32, t.ObjectPaging.PageIndex);
                //Add value PageSize  paramater.
                ManagerDao.AddInParameter(cmd, "PageSize", DbType.Int32, t.ObjectPaging.PageSize);
                //Add value SortField  paramater.
                ManagerDao.AddInParameter(cmd, "SortField", DbType.String, t.ObjectSortOrder.SortField);
                //Add value SortExpression  paramater.
                ManagerDao.AddInParameter(cmd, "SortExpression", DbType.String, t.ObjectSortOrder.SortExpression);
                using (IDataReader reader = ManagerDao.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        listMatHang.Add(GetMatHangResultByDataReader(reader));
                        if (t.ToltalRow <= 0)
                            t.ToltalRow = ManagerDao.Getint32DataFromDataReader(reader, "TotalRow");
                    }

                    reader.Close();
                }

                return listMatHang;
            }
            catch (Exception ex)
            {
                //write error message to log file.
                logger.Error(methodName, ex);
                return null;
            }
        }
        public static List<MatHangResult> SearchMatHangFormListMH(MatHang t)
        {
            String methodName = "SearchMatHangFormListMH";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }

            try
            {
                List<MatHangResult> listMatHang = new List<MatHangResult>();
                DbCommand cmd = ManagerDao.GetStoredProcCommand("spSearchMatHangFormListMH");
                //Add value Condition  paramater.
                ManagerDao.AddInParameter(cmd, "Condition", DbType.String, ConvertValueObject.CastObjValueToInsertDB(t.Condition));

                //Add value PageIndex  paramater.
                ManagerDao.AddInParameter(cmd, "PageIndex", DbType.Int32, t.ObjectPaging.PageIndex);
                //Add value PageSize  paramater.
                ManagerDao.AddInParameter(cmd, "PageSize", DbType.Int32, t.ObjectPaging.PageSize);
                //Add value SortField  paramater.
                ManagerDao.AddInParameter(cmd, "SortField", DbType.String, t.ObjectSortOrder.SortField);
                //Add value SortExpression  paramater.
                ManagerDao.AddInParameter(cmd, "SortExpression", DbType.String, t.ObjectSortOrder.SortExpression);
                using (IDataReader reader = ManagerDao.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        listMatHang.Add(GetMatHangResultByDataReader(reader));
                        if (t.ToltalRow <= 0)
                            t.ToltalRow = ManagerDao.Getint32DataFromDataReader(reader, "TotalRow");
                    }

                    reader.Close();
                }

                return listMatHang;
            }
            catch (Exception ex)
            {
                //write error message to log file.
                logger.Error(methodName, ex);
                return null;
            }
        }
        /// <summary>
        /// Delete MatHang object. 
        /// </summary>
        /// <param name="MaMatHang" >This is primary key to delete.</param>
        /// <returns>True/False.</returns>

        public static bool Delete(string MaMatHang)
        {
            String methodName = "DeleteMatHang";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }

            try
            {
                DbCommand dbCommand = ManagerDao.GetStoredProcCommand("spDeleteMatHang");
                //Add value "MaMatHang"  paramater.
                ManagerDao.AddInParameter(dbCommand, "MaMatHang", DbType.AnsiString, MaMatHang);
                //Add value returnValue  paramater.
                ManagerDao.AddParameter(dbCommand, "returnValue", DbType.Int32, ParameterDirection.ReturnValue, string.Empty, DataRowVersion.Default, null);
                try
                {
                    ManagerDao.ExecuteNonQuery(dbCommand);
                    int parameterValue = (int)ManagerDao.GetParameterValue(dbCommand, "returnValue");
                    if (parameterValue == 1)
                    {
                        return true;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                return false;
            }
            catch (Exception e)
            {
                //write error message to log file.
                logger.Error(methodName, e);
                return false;
            }
        }
        /// <summary>
        /// Read data from IDataReader, convert to MatHangResult Object.
        /// </summary>
        private static MatHangResult GetMatHangResultByDataReaderByLanguage(IDataReader reader, string LanguageId)
        {
            String methodName = "GetMatHangResultByDataReader";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }
            try
            {
                MatHangResult result = new MatHangResult();
                //read MaMatHang field data.
                result.MaMatHang = ManagerDao.GetstringDataFromDataReader(reader, "MaMatHang");

                //read MaLoaiHangHoa field data.
                result.MaLoaiHangHoa = ManagerDao.GetintDataFromDataReader(reader, "MaLoaiHangHoa");

                //read TenMatHang field data.
                result.TenMatHang = ManagerDao.GetstringDataFromDataReader(reader, "TenMatHang");

                //read MaNuocSanXuat field data.
                result.MaNuocSanXuat = ManagerDao.GetintDataFromDataReader(reader, "MaNuocSanXuat");

                //read Hieu field data.
                result.Hieu = ManagerDao.GetstringDataFromDataReader(reader, "Hieu");

                //read GhiChu field data.
                result.GhiChu = ManagerDao.GetstringDataFromDataReader(reader, "GhiChu");

                //read Order field data.
                result.Order = ManagerDao.GetintDataFromDataReader(reader, "Order");

                //read IsPublished field data.
                result.IsPublished = ManagerDao.GetbooleanDataFromDataReader(reader, "IsPublished");

                //read CreatedBy field data.
                result.CreatedBy = ManagerDao.GetstringDataFromDataReader(reader, "CreatedBy");

                //read CreatedDate field data.
                result.CreatedDate = ManagerDao.GetdatetimeDataFromDataReader(reader, "CreatedDate");

                //read LastUpdatedBy field data.
                result.LastUpdatedBy = ManagerDao.GetstringDataFromDataReader(reader, "LastUpdatedBy");

                //read LastUpdatedDate field data.
                result.LastUpdatedDate = ManagerDao.GetdatetimeDataFromDataReader(reader, "LastUpdatedDate");

                return result;
            }
            catch (Exception e)
            {
                // write error to log file.
                logger.Error(methodName, e);
                return null;
            }
        }
        /// <summary>
        /// Read data from IDataReader, convert to MatHangResult Object.
        /// </summary>
        protected static MatHangResult GetMatHangResultByDataReader(IDataReader reader)
        {
            String methodName = "GetMatHangResultByDataReader";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }
            try
            {
                MatHangResult result = new MatHangResult();
                //read MaMatHang field data.
                result.MaMatHang = ManagerDao.GetstringDataFromDataReader(reader, "MaMatHang");

                //read MaLoaiHangHoa field data.
                result.MaLoaiHangHoa = ManagerDao.GetintDataFromDataReader(reader, "MaLoaiHangHoa");
                result.MaPhuTung = ManagerDao.GetstringDataFromDataReader(reader, "MaPhuTung");

                //read TenMatHang field data.
                result.TenMatHang = ManagerDao.GetstringDataFromDataReader(reader, "TenMatHang");
                result.TenLoaiMatHang = ManagerDao.GetstringDataFromDataReader(reader, "TenLoaiMatHang");

                //read MaNuocSanXuat field data.
                result.MaNuocSanXuat = ManagerDao.GetintDataFromDataReader(reader, "MaNuocSanXuat");

                //read Hieu field data.
                result.Hieu = ManagerDao.GetstringDataFromDataReader(reader, "Hieu");

                //read GhiChu field data.
                result.GhiChu = ManagerDao.GetstringDataFromDataReader(reader, "GhiChu");

                //read Order field data.
                result.Order = ManagerDao.GetintDataFromDataReader(reader, "Order");
                //read DVT field data.
                result.DVT = ManagerDao.GetintDataFromDataReader(reader, "DVT");

                //read IsPublished field data.
                result.IsPublished = ManagerDao.GetbooleanDataFromDataReader(reader, "IsPublished");

                //read CreatedBy field data.
                result.CreatedBy = ManagerDao.GetstringDataFromDataReader(reader, "CreatedBy");

                //read CreatedDate field data.
                result.CreatedDate = ManagerDao.GetdatetimeDataFromDataReader(reader, "CreatedDate");

                //read LastUpdatedBy field data.
                result.LastUpdatedBy = ManagerDao.GetstringDataFromDataReader(reader, "LastUpdatedBy");

                //read LastUpdatedDate field data.
                result.LastUpdatedDate = ManagerDao.GetdatetimeDataFromDataReader(reader, "LastUpdatedDate");

                return result;
            }
            catch (Exception e)
            {
                // write error to log file.
                logger.Error(methodName, e);
                return null;
            }
        }
        protected static MatHangResult GetMatHangResultInDMMatHangByDataReader(IDataReader reader)
        {
            String methodName = "GetMatHangResultInDMMatHangByDataReader";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }
            try
            {
                MatHangResult result = new MatHangResult();
                //read MaMatHang field data.
                result.MaMatHang = ManagerDao.GetstringDataFromDataReader(reader, "MaMatHang");
                result.MaPhuTung = ManagerDao.GetstringDataFromDataReader(reader, "MaPhuTung");
                //read TenMatHang field data.
                result.TenMatHang = ManagerDao.GetstringDataFromDataReader(reader, "TenMatHang");
                //read IsPublished field data.
                result.IsPublished = ManagerDao.GetbooleanDataFromDataReader(reader, "IsPublished");               

                return result;
            }
            catch (Exception e)
            {
                // write error to log file.
                logger.Error(methodName, e);
                return null;
            }
        }
    }
}